package IO;
//字节转字符流
//通过new 文件输出流传到write方法中，然后Write write = new OutputStreamWriter(文件输出流,默认字符编码（）)
import java.io.*;
import java.nio.charset.Charset;

public class chartobyte {

    private static void read(InputStream in){
        Reader reader = new InputStreamReader(in, Charset.defaultCharset());
        char[] chars = new char[1024];
        int len=-1;
        try {
            while ((len=reader.read(chars))!=-1){
                System.out.print(new String(chars,0,len));
            }
            reader.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    private static void write(OutputStream out){
        Writer writer = new OutputStreamWriter(out,Charset.defaultCharset());
        try {
            writer.write("开开心心拉完屎111\r\n");
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public static void main(String[] args) throws FileNotFoundException {
        InputStream is = new FileInputStream("C:\\Users\\Administrator\\Desktop\\新建文件夹 (2)\\14141.txt");
        OutputStream os = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\新建文件夹 (2)\\14141.txt",true);
               write(os);
               read(is);

        }
    }

